package com.szt.mobile.inventory.common.entity;

import org.greenrobot.greendao.DaoException;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.ToMany;

import java.util.List;

/**
 * Created by yanzhaodi on 2017/11/16.
 */
@Entity(nameInDb = "t_assetslist")
public class AssetsList extends BaseEntity {

    @Id
    public Long _id;

    public Long inventoryId;

    @ToMany(referencedJoinProperty = "assetsListId")
    public List<Assets> asset;

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 697093156)
    public synchronized void resetAsset() {
        asset = null;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1645131093)
    public List<Assets> getAsset() {
        if (asset == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            AssetsDao targetDao = daoSession.getAssetsDao();
            List<Assets> assetNew = targetDao._queryAssetsList_Asset(_id);
            synchronized (this) {
                if(asset == null) {
                    asset = assetNew;
                }
            }
        }
        return asset;
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 2098297970)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getAssetsListDao() : null;
    }

    /** Used for active entity operations. */
    @Generated(hash = 327126973)
    private transient AssetsListDao myDao;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    public Long getInventoryId() {
        return this.inventoryId;
    }

    public void setInventoryId(Long inventoryId) {
        this.inventoryId = inventoryId;
    }

    public Long get_id() {
        return this._id;
    }

    public void set_id(Long _id) {
        this._id = _id;
    }

    @Generated(hash = 581527374)
    public AssetsList(Long _id, Long inventoryId) {
        this._id = _id;
        this.inventoryId = inventoryId;
    }

    @Generated(hash = 24887572)
    public AssetsList() {
    }
}
